package com.xyz.service;

import com.free.ext.mybatis.model.entity.PageResponseModel;
import com.free.utils.DateUtils;
import com.xyz.dao.logic.SLotteryLogic;
import com.xyz.dao.logic.SLotteryPeriodLogic;
import com.xyz.domain.model.LotteryPeriodSearchModel;
import com.xyz.domain.model.LotteryPeriodSearchResModel;
import com.xyz.domain.table.SLottery;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class YldtService extends BaseService {

    @Autowired
    SLotteryPeriodLogic lotteryPeriodLogic;

    @Autowired
    LotteryInfoService lotteryInfoService;

    //获得当前抽奖信息
    public PageResponseModel<LotteryPeriodSearchResModel> selectPeriodPageInfo(LotteryPeriodSearchModel condition, String orderBy, int pageNo, int pageSize){
        return lotteryPeriodLogic.selectPeriodPageInfo(condition,orderBy,pageNo,pageSize);
    }

    public PageResponseModel<LotteryPeriodSearchResModel> getTodayLotteryInfo(LotteryPeriodSearchModel condition, int pageNo, int pageSize){
        SLottery lotteryInfo = lotteryInfoService.getLotteryInfo(condition.getLotteryCode());
        if(lotteryInfo == null){
            return null;
        }
        condition.setCustId(getCurrentUser().getId());
        udpConditionModel(lotteryInfo, condition);
        String orderBy = " startTime desc ";
        return lotteryPeriodLogic.getTodayLotteryInfo(condition, orderBy, pageNo, pageSize);
    }





    private void udpConditionModel(SLottery lotteryInfo, LotteryPeriodSearchModel condition){
        int seconds = 0;
        if(lotteryInfo.getStepMins() != null || lotteryInfo.getStepMins() > 0){
            seconds += lotteryInfo.getStepMins() * 60;
        }
        if(lotteryInfo.getStepSecs() != null || lotteryInfo.getStepSecs() > 0){
            seconds += lotteryInfo.getStepSecs();
        }
        Date serTime = DateUtils.nextSecond(DateUtils.getCurrentDate(), seconds);
        condition.setSerTime(serTime);
    }


    
}
